package com.xxzb.pack0720;

import java.sql.*;

//实现查询效果
public class DemoE {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql:///gaofeng2207?useSSL=false";
        String username="root";
        String password="1234";
        Connection conn= DriverManager.getConnection(url,username,password);
        String sql="select * from gaofeng2207.emp where empstate=1";
        PreparedStatement ps=conn.prepareStatement(sql);
        //执行查询操作并返回结果集
        ResultSet rs = ps.executeQuery();
        while (rs.next()){
            //rs就是下一行信息
            int empNo=rs.getInt(1);//获取第一列内容，员工编号，通过列号获取
            String ename=rs.getString("ename");//获取第二列内容，员工姓名，通过列名获取
            String job=rs.getString("job");
            int mgr=rs.getInt(4);
            String hireDate=rs.getString(5);
            double sal=rs.getDouble(6);
            double comm=rs.getDouble(7);
            int deptNo=rs.getInt(8);
            int empState=rs.getInt("empstate");
            System.out.print(empNo+"\t");
            System.out.print(ename+"\t");
            System.out.print(job+"\t");
            System.out.print(mgr+"\t");
            System.out.print(hireDate+"\t");
            System.out.print(sal+"\t");
            System.out.print(comm+"\t");
            System.out.print(deptNo+"\t");
            System.out.println(empState+"\n");

        }
    }
}
